package im.oen.gui.tools.util;

import im.oen.boot.common.utils.Checker;
import im.oen.gui.tools.component.JPassword;

import javax.swing.*;
import java.awt.*;

/**
 * @author Kevin.Xu
 */
public class SwingUtil {

    public static JButton createButton(String text) {
        JButton button = new JButton();
        button.setText(text);
        return button;
    }

    public static JButton createButton(String text, int x, int y, int w, int h) {
        JButton button = new JButton();
        button.setText(text);
        button.setBounds(x, y, w, h);
        return button;
    }

    public static JLabel createLabel(String text) {
        return new JLabel(text);
    }

    public static JLabel createLabel(String text, int x, int y, int w, int h) {
        JLabel label = new JLabel(text);
        label.setBounds(x, y, w, h);
        return label;
    }

    public static JTextField createTextField(int x, int y, int w, int h) {
        JTextField txt = new JTextField();
        txt.setBounds(x, y, w, h);
        return txt;
    }

    public static JTextField createTextField(String defaultValue, int x, int y, int w, int h) {
        JTextField txt = new JTextField(defaultValue);
        txt.setBounds(x, y, w, h);
        return txt;
    }

    public static JPassword createTextField(char pass, int x, int y, int w, int h) {
        JPassword txt = new JPassword();
        txt.setEchoChar(pass);
        txt.setBounds(x, y, w, h);
        return txt;
    }

    public static JPanel createPanel() {
        JPanel panel = new JPanel();
        panel.setBackground(Color.WHITE);
        return panel;
    }

    public static void setColor(Component component, Color color) {
        if (Checker.hasEmpty(component, color)) {
            return;
        }
        component.setBackground(color);
    }
}
